﻿<Window x:Class="Chem4Word.UI.TwoD.AddLabelWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:TwoD="clr-namespace:Chem4Word.UI.TwoD" Title="Add Label" Height="68" Width="270" x:Name="self" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow">
	<Window.Resources>
		<Style TargetType="{x:Type TextBox}" x:Key="TextBoxErrorStyle">
			<Setter Property="Validation.ErrorTemplate">
				<Setter.Value>
					<ControlTemplate>
						<AdornedElementPlaceholder />
					</ControlTemplate>
				</Setter.Value>
			</Setter>
			<Style.Triggers>
				<Trigger Property="Validation.HasError" Value="true">
					<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, 
                       Path=(Validation.Errors)[0].ErrorContent}" />
					<Setter Property="Background" Value="Pink" />
				</Trigger>
			</Style.Triggers>
		</Style>
	</Window.Resources>
	<StackPanel Orientation="Horizontal">
		<!--<TextBox x:Name="_textBox" Margin="4,4,4,4" Text="{Binding ElementName=self, Path=LabelText}" Width="150" Height="auto"/>-->
		<TextBox x:Name="textBox" Margin="4,4,4,4" Width="150" Height="auto" Style="{StaticResource TextBoxErrorStyle}">
			<TextBox.Text>
				<Binding x:Name="textBinding" ElementName="self" Path="LabelText" UpdateSourceTrigger="PropertyChanged">
					<Binding.ValidationRules>
						<TwoD:LabelValidationRule ValidatesOnTargetUpdated="True" />
					</Binding.ValidationRules>
				</Binding>
			</TextBox.Text>
		</TextBox>
		<Button x:Name="OKButton" Content="OK" Margin="4,4,4,4" IsDefault="True" Width="80" Click="Button_Click">
			<Button.Style>
				<Style TargetType="{x:Type Button}">
					<Setter Property="IsEnabled" Value="false" />
					<Style.Triggers>
						<!-- Require the controls to be valid in order to press OK -->
						<MultiDataTrigger>
							<MultiDataTrigger.Conditions>
								<Condition Binding="{Binding ElementName=textBox, Path=(Validation.HasError)}" Value="false" />
							</MultiDataTrigger.Conditions>
							<Setter Property="IsEnabled" Value="true" />
						</MultiDataTrigger>
					</Style.Triggers>
				</Style>
			</Button.Style>
		</Button>

	</StackPanel>
</Window>